﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIText : MonoBehaviour
{
    public Text starsText;

    public int GetTotalStars()
    {
        int sum = 0;
        for (int i = 1; i <= 8; i++)
        {
            sum += PlayerPrefs.GetInt("Lv" + i.ToString(), 0); // 使用默认值0，以防键不存在
        }
        return sum;
    }

    private void Update()
    {
        UpdateStarsUI();
    }

    //private void UpdateStarsUI()
    //{
    //    int sum = 0;
    //    for(int i = 1; i <= 8; i++)
    //    {
    //        sum += PlayerPrefs.GetInt("Lv" + i.ToString());
    //    }

    //    starsText.text = sum + "/"+ 24;
    //}

    private void UpdateStarsUI()
    {
        int totalStars = GetTotalStars();
        starsText.text = totalStars + "/" + 24;
    }
}
